package com.neu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements  View.OnClickListener {

    //定义一个textview对象
    private TextView tvHello;
    //定义一个按钮对象
    private Button btnMy;



    //定义btnView
    private Button btnView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获得textView对象的实例
        tvHello=this.findViewById(R.id.tvHello);
        tvHello.setText("我修改了Textview的值");

        //接收来的数据
        Intent intent=getIntent();
        String str=intent.getStringExtra("str");

        Bundle bundle=intent.getBundleExtra("bd");
        int myInt=intent.getIntExtra("myInt",0);
        tvHello.setText(str+myInt+"  "+bundle.getString("myBundle"));


        //获得按钮对象的引用
        btnMy=this.findViewById(R.id.btnMy);
        btnMy.setText("我的按钮");
        //按钮事件对应的监听
        btnMy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //在监听的接口方法中编写代码
                tvHello.setText("按钮点击了，发生的鼠标单击事件");
            }
        });

        //实例化btnView
        btnView=findViewById(R.id.btnView);
        //添加监听程序
        btnView.setOnClickListener(this);

    }

    public void btnClick(View view) {
        tvHello.setText("btn按钮触发的代码");
    }

    //接口实现的方法
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btnView:{
                tvHello.setText("btnView点击了");
                break;
            }
        }



      //  Log.d("TAG", "onClick: "+view.getId());

    }

    public void btnIntentClick(View view) {
        Intent intent=new Intent();
        intent.setAction("android.intent.action.Test");
        intent.addCategory("android.intent.category.DEFAULT");
        startActivity(intent);

    }

    @Override
    public void onBackPressed() {
        Intent intent=new Intent();
        intent.putExtra("back","我是来自main");
        setResult(110,intent);
        super.onBackPressed();
    }
}